package com.pub.cloud.system.status.controller;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;


@Component
public class ScheduledDeleteData {
	private static final Logger logger = LogManager.getLogger(ScheduledDeleteData.class);
	
	@Value("${source-url}")
	private String sourceUrl;
	@Value("${scheduled-delete-sql}")
	private String scheduledDeleteSql;
	@Value("${user-name}")
	private String userName;
	@Value("${password}")
	private String password;
	
//	@Scheduled(fixedRate = 6000)
	@Scheduled(fixedRate = 600000)
	public void scheduledCheckEsSyn() {
		Statement stmt = null;
		Connection conn = null;
		try {
			Class.forName("org.h2.Driver");
			conn = DriverManager.getConnection(
					sourceUrl, userName,
					password);
			stmt = conn.createStatement();
			stmt.executeUpdate(scheduledDeleteSql);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (stmt != null) {
					stmt.close();
					stmt = null;
				}
				if (conn != null) {
					conn.close();
					conn = null;
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}		
	}
}
